package cn.fyl.controller;

import cn.fyl.block.BlockUser;
import cn.fyl.domain.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sun.deploy.security.BlockedException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
// 配置自动刷新注解
@RefreshScope
public class UserController {

    @Value("${test.name}")
    private String name;

    @GetMapping("/getById/{id}")
    // 设置限流的注解
    @SentinelResource(value = "user-getById",blockHandler = "blockUserMethod",blockHandlerClass = BlockUser.class)
    public User getById(@PathVariable("id") Long id){
        return new User(id,"佘豆传媒","成都一级代理商"+name);
    }
    //
    /*public User blockUserMethod(@PathVariable("id") Long id , BlockException e){
        e.printStackTrace();
        return new User(-1L,"限流了","遭不住了");
    }*/
}
